﻿#region [StartUpPage Using Statements]
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel;
using System.Windows.Threading;
using ControlPanelOOB.AccelerometerService;
#endregion

namespace ControlPanelOOB
{
    /// <summary>
    /// This UserControl represents the Starter Page for the OOB application.
    /// It will load a small animation and when it finishes it will show a message,
    /// start the LoadingControl animation and call the animation has finished event
    /// </summary>
	public partial class StartUpPage : UserControl
    {
        #region [StartUpPage Events]
        public delegate void PageLoadedEventHandler(object sender, EventArgs e);
        public event PageLoadedEventHandler PageLoaded;       
        #endregion

        #region [StartUpPage Constructor]
        /// <summary>
        /// StartUpPage Constructor
        /// </summary>
        public StartUpPage()
        {
            // Required to initialize variables
            InitializeComponent();

            this.Loaded += new System.Windows.RoutedEventHandler(Start_Loaded);
            this.StartingAppStoryboard.Completed += new System.EventHandler(StartingAppStoryboard_Completed);
        }
        #endregion

        #region [StartUpPage EventHandlers]
        /// <summary>
        /// EventHandler triggered when this control has been loaded
        /// </summary>
        /// <param name="sender">Who triggered the event</param>
        /// <param name="e">Default RoutedEventArgs</param>
        private void Start_Loaded(object sender, RoutedEventArgs e)
		{
			StartingAppStoryboard.Begin();
		}
		
        /// <summary>
        /// EventHandler triggered when the animation finishes
        /// </summary>
        /// <param name="sender">Who triggered the event</param>
        /// <param name="e">Default EventArgs</param>
        private void StartingAppStoryboard_Completed(object sender, EventArgs e)
        {
            InfoTextBlock.Visibility = Visibility.Visible;
            LoadingControl.StartAnimation();

            if (PageLoaded != null)
                PageLoaded(this, null);
        }
        #endregion

        #region [StartUpPage Public Methods]
        /// <summary>
        /// Sets the message that informs the user what's going on.
        /// </summary>
        /// <param name="msg">Message to show</param>
        /// <remarks>
        /// Initially it will say it's looking for the WP7
        /// XNA Accelerometer Simulator and if we find that the 
        /// application is open, we change the message accordingly
        /// </remarks>
        public void ChangeLoadingMessage(string msg)
        {
            InfoTextBlock.Text = msg;
        }
        #endregion
    }
}